﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;
using DTO;

namespace DAO
{
    public class DAO_Sach
    {
        #region Sach
        public static int capnhatsach(string sql)
        {
            OleDbCommand cmd = new OleDbCommand();
            cmd.CommandText = sql;
            cmd.Connection = DataProvider.c;
            return cmd.ExecuteNonQuery();
            
        }        

        public static bool themsach(DTO_Sach s)
        {
            string truyvan = string.Format("insert into sach(tensach,tacgia,gia,ngaynhap,manv,maloaisach) values('" + s.TenSach + "',"+s.TacGia+","+s.Gia+",'"+s.NgayNhap+"',"+s.ManNV+","+s.MaLoaiSach+")");
            if (DataProvider.Capnhatdl(truyvan) > 0)
            {
                return true;
            }
            return false;
        }
        public static bool xoasach(DTO_Sach s)
        {
            string truyvan = string.Format("delete from sach where masach =" + s.Masach);
            if (DataProvider.Capnhatdl(truyvan) > 0)
            {
                return true;
            }
            return false;
        }
        public static bool suasach(DTO_Sach s)
        {
            string truyvan = string.Format("update sach set tensach='" + s.TenSach + "',tacgia='"+s.TacGia+"',ngaynhap='"+s.NgayNhap+"',manv="+s.ManNV+",maloaisach="+s.MaLoaiSach+" where masach=" + s.Masach);
            if (DataProvider.Capnhatdl(truyvan) > 0)
            {
                return true;
            }
            return false;
        }


        public static DataTable LayDSSach() {
            return DataProvider.laydulieubang("SELECT Sach.* FROM TacGia INNER JOIN (NhanVien INNER JOIN (LoaiSach INNER JOIN Sach ON LoaiSach.MaLoaiSach = Sach.MaLoaiSach) ON NhanVien.MaNV = Sach.MaNV) ON TacGia.MaTG = Sach.TacGia", DataProvider.c);
        }
        #endregion
    }
}
